package com.cc.cbdb.view.x5WebView;

import android.app.Activity;
import android.content.Intent;
import android.webkit.JavascriptInterface;

import com.cc.cbdb.activity.SearchActivity;
import com.cc.cbdb.common.constants.Constant;
import com.cc.cbdb.common.report.ReportHelper;

/**
 * Created by tollcc on 2018/3/24.
 */

public class Android2Js extends Object{

    private Activity mActivity;
    private ReportHelper reportHelper;

    public Android2Js(Activity activity){
        this.mActivity = activity;
        reportHelper = ReportHelper.getInstance(mActivity);
    }

    @JavascriptInterface
    public void queryBiogAddr(String cAddrId,String cAddrTypes){
        reportHelper.reportQueryState(ReportHelper.ADDRESS,cAddrId,null);
        reportHelper.reportQueryState(ReportHelper.ADDRTYPE,cAddrTypes,null);

        Intent intent = new Intent(mActivity, SearchActivity.class);
        intent.putExtra("title", Constant.TITLE.TITLE_QBIOGADDR);
        intent.putExtra("isShowSeachView",false);
        intent.putExtra("isLoading",true);
        intent.putExtra("param1",cAddrId);
        intent.putExtra("param2",cAddrTypes);
        mActivity.startActivity(intent);
    }

    @JavascriptInterface
    public void queryOffNameCustom(String officeId,String entryId,String tempId){
        reportHelper.reportQueryState(ReportHelper.OFFICE,officeId,tempId);
        reportHelper.reportQueryState(ReportHelper.ENTRYTYPE,entryId,null);

        Intent intent = new Intent(mActivity, SearchActivity.class);
        intent.putExtra("title",Constant.TITLE.TITLE_QBIOGOFF);
        intent.putExtra("isShowSeachView",false);
        intent.putExtra("isLoading",true);
        intent.putExtra("param1",officeId);
        intent.putExtra("param2",entryId);
        intent.putExtra("param3",tempId);
        mActivity.startActivity(intent);
    }

    @JavascriptInterface
    public void selectFromHtml(int resultCode,String param1,String param2,String param3){
        Intent intent = new Intent();
        intent.putExtra("param1",param1);
        intent.putExtra("param2",param2);
        intent.putExtra("param3",param3);
        mActivity.setResult(resultCode,intent);
        mActivity.finish();
    }
}
